<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\MyCoupon;
use App\Shop;
use App\UserInfo;
use App\ShopCoupon;
use Input;
class MyCouponController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //获取所有的信息
        $datas = MyCoupon::select('mycoupon.id','mycoupon.keys','mycoupon.sendstatus','userinfo.username')
            ->join('userinfo','userinfo.uid','=','mycoupon.uid')
            ->paginate('30');
        return view('admin.mycoupon.index',compact('datas'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //根据id获取所有信息
        $datas = MyCoupon::select('mycoupon.*','shops.shopname','userinfo.username','shops_coupon.title')
            ->join('shops','shops.shopid','=','mycoupon.shopid')
            ->join('userinfo','userinfo.uid','=','mycoupon.uid')
            ->join('shops_coupon','shops_coupon.cid','=','mycoupon.cid')
            ->first();
        return view('admin.mycoupon.show',compact('datas'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //获取id
        dd($id);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //直接删除内容
        $res = MyCoupon::destroy($id);
        if($res)
        return Response() -> json(['status'=>'success','msg'=>'删除成功']);
        return Response() -> json(['status'=>'error','msg'=>'删除失败']);
    }
}
